package interfases;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import controladores.ControladorPerfil;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Color;
import java.awt.Toolkit;

import javax.swing.SwingConstants;

public class IModificarPerfil extends JFrame {
	
	private static final long serialVersionUID = 1L;
	private JPanel caja;
	private JTextField campoNick;
	private JLabel lblNick;
	private JButton aceptar;
	private JButton cancelar;
	private JTextField txtModificarPerfil;

	
	//CENTRA LA PANTALLA PRINCIPAL
		private void centrarPantalla(JFrame ventana, int x, int y){
			Toolkit t = Toolkit.getDefaultToolkit();
			Dimension pantalla = t.getScreenSize();
			int height = pantalla.height;
			int width = pantalla.width;
			int px =  (int) (width-x)/2;
			int py =  (int) (height-y)/2;
			ventana.setBounds(px, py, x, y);
		}
	
	
	
	public IModificarPerfil() {
		
		setBackground(Color.GRAY);
		setTitle("Modificacion de Perfil");
		setResizable(false);
		centrarPantalla(this, 480, 250);
		caja = new JPanel();
		caja.setBackground(new Color(255, 222, 173));
		caja.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(caja);
		caja.setLayout(null);
		
		lblNick = new JLabel("Ingrese Nick");
		lblNick.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNick.setFont(new Font("Eras Medium ITC", Font.PLAIN, 14));
		lblNick.setBounds(12, 104, 123, 20);
		caja.add(lblNick);
		campoNick = new JTextField();
		campoNick.setBounds(145, 105, 283, 20);
		caja.add(campoNick);
		campoNick.setColumns(10);
		aceptar = new JButton("Aceptar");
		aceptar.setFont(new Font("Eras Medium ITC", Font.PLAIN, 15));
		aceptar.setBounds(250, 186, 100, 23);
		caja.add(aceptar);
		cancelar = new JButton("Cancelar");
		cancelar.setFont(new Font("Eras Medium ITC", Font.PLAIN, 15));
		cancelar.setBounds(362, 186, 100, 23);
		caja.add(cancelar);
		
		txtModificarPerfil = new JTextField();
		txtModificarPerfil.setText("Modificar Perfil");
		txtModificarPerfil.setHorizontalAlignment(SwingConstants.CENTER);
		txtModificarPerfil.setForeground(new Color(255, 255, 255));
		txtModificarPerfil.setFont(new Font("Eras Medium ITC", Font.BOLD, 20));
		txtModificarPerfil.setEnabled(false);
		txtModificarPerfil.setEditable(false);
		txtModificarPerfil.setBackground(new Color(128, 0, 0));
		txtModificarPerfil.setBounds(0, 0, 474, 50);
		caja.add(txtModificarPerfil);
		txtModificarPerfil.setColumns(10);
		
		
	/**********************************************************************************************/
		
		//ACCION DEL BOTON CONFIRMAR NICK
		aceptar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nick = campoNick.getText().toUpperCase();
				ControladorPerfil cp= new ControladorPerfil();				
			
				if(cp.existeNick(nick)){
					dispose();
					IModificarPerfil_2 frame = new IModificarPerfil_2(nick);
					frame.setVisible(true);
				}
				else{
					JOptionPane.showMessageDialog(null,"No existe el Nick "+nick);
				}
			}
		});
		
		//ACCION DEL BOTON CANCELAR
		cancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		
	}
}
